/* - IFKitDetachListener - 
 * Here we display the status, which will be false as the device is not attached.
 * We will also clear the display fields and hide the inputs and outputs.
 *
 * Copyright 2007 Phidgets Inc.  
 * This work is licensed under the Creative Commons Attribution 2.5 Canada License. 
 * To view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
 */
package listeners;

import com.phidgets.InterfaceKitPhidget;

import com.phidgets.PhidgetException;
import com.phidgets.event.DetachListener;
import com.phidgets.event.DetachEvent;
import javax.swing.JButton;


import javax.swing.JFrame;

import javax.swing.JOptionPane;

import javax.swing.JTextField;

public class IFKitDetachListener implements DetachListener {

    private JFrame m_appFrame;
    private JTextField m_attachedTxt;
    private JButton m_startButton;

    /** Creates a new instance of IFKitDetachListener */
    public IFKitDetachListener(JFrame appFrame, JTextField attachedTxt, JButton startButton) {
        m_appFrame = appFrame;
        m_attachedTxt = attachedTxt;
        m_startButton = startButton;
    }

    public void detached(DetachEvent ae) {
        try {
            InterfaceKitPhidget detached = (InterfaceKitPhidget) ae.getSource();
            m_attachedTxt.setText(Boolean.toString(detached.isAttached()));
            m_startButton.setEnabled(false);
        } catch (PhidgetException ex) {
            JOptionPane.showMessageDialog(m_appFrame, ex.getDescription(), "Phidget error " + ex.getErrorNumber(), JOptionPane.ERROR_MESSAGE);
        }
    }
}
